<template>
    <el-dialog title="模板" :close-on-click-modal="false" :before-close="closeDailog" :visible.sync="visible"
        append-to-body>
        <!-- 表格表体 -->
        <ec-table :data="tabledata">
            <el-table-column prop="templateName" header-align="center" align="center" show-overflow-tooltip
                label="模板名称">
            </el-table-column>
            <el-table-column prop="moduleValue" header-align="center" align="center" show-overflow-tooltip label="模块编号">
            </el-table-column>
            <el-table-column prop="version" header-align="center" align="center" show-overflow-tooltip label="版本">
            </el-table-column>
            <el-table-column prop="note" header-align="center" align="center" show-overflow-tooltip label="描述">
            </el-table-column>
            <el-table-column fixed="right" header-align="center" align="center" width="120" label="操作">
                <template slot-scope="scope">
                    <el-button type="text" size="small" @click="downloadHandler(scope.row)"
                        class="el-icon-download" v-if="isAuth()">下载
                    </el-button>
                </template>
            </el-table-column>

        </ec-table>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeDailog()">取消</el-button>
        </span>
    </el-dialog>
</template>

<script>
    import * as dataimporttemplateService from '@/api/report/dataimporttemplate'
    import * as fileService from '@/api/file/file'
    export default {
        data() {
            return {
                searchForm: {
                    type: '',
                    name: '',
                },
                page: {
                    page: 1,
                    limit: 10,
                    total: 0
                },
                visible: false,
                showHeader: false,
                tabledata: [],
                multipleSelection: [],
                loading: false,
                addOrUpdateVisible: false,
                submitLoading: false
            }
        },
        components: {},
        mounted() {
            this.getDataTable()
        },
        methods: {
            init(tabledata) {
                this.visible = true
                this.$nextTick(() => {
                    console.log("加载模板")
                    this.getDataTable(tabledata)
                })
            },
            // 获取数据列表
            getDataTable(moduleValue) {
                this.loading = true
                let query = {
                    moduleValue: moduleValue
                };
                dataimporttemplateService.getDataImportTemplateList(query).then(data => {
                    this.tabledata = data;
                    this.loading = false;
                }).catch((res) => {
                    this.loading = false;
                });
            },
            downloadHandler(file) {
                let params = "fileIds=" + file.pkFile;
                fileService.download(params).then(data => {
                    this.$downloadFile(data, file.templateName)
                })
            },
            closeDailog() {
                this.tabledata = []
                this.visible = false
            }
        }
    }
</script>